package util

func Ptr(val any) *any {
	return &val
}
func InArray[T comparable](array []T, search T) bool {
	if len(array) == 0 {
		return false
	}

	for _, v := range array {
		if v == search {
			return true
		}
	}

	return false
}

func Filter[Any any](items []Any, function func(Any) bool) []Any {
	result := []Any{}

	for _, item := range items {
		if function(item) {
			result = append(result, item)
		}
	}

	return result
}
func Map[Src, Dst any](items []Src, function func(Src) Dst) []Dst {
	result := make([]Dst, 0, len(items))

	for _, item := range items {
		result = append(result, function(item))
	}

	return result
}
func Reduce[Src, Dst any](items []Src, initializer Dst, function func(Dst, Src) Dst) Dst {
	result := initializer

	for _, item := range items {
		result = function(result, item)
	}

	return result
}

func GetX[T any]() T {
	var t T

	var ti interface{} = &t
	switch v := ti.(type) {
	case *int:
		*v = 18
	}

	return t
}
